package component

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commConfig"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Map"
)

type dataTypeService struct {
}

func (e *dataTypeService) GetDataType(manufacturer, deviceType, publish string) string {
	configValue, err := commConfig.GetConfigParam("serverConfig")
	if err != nil {
		return "rt"
	}

	// 取出全局配置参数
	dataTypes := Map.GetSlice(configValue, "dataTypes", make([]interface{}, 0))
	for _, val := range dataTypes {
		data := val.(map[string]interface{})

		if manufacturer != Map.GetString(data, "manufacturer", "") {
			continue
		}
		if deviceType != Map.GetString(data, "deviceType", "") {
			continue
		}
		dataType := Map.GetString(data, "dataType", "rt")

		if "eigenvalue" != dataType && "rt" != dataType {
			return "rt"
		}
		return dataType
	}

	return "rt"
}
